package com.asset.dispoal.file.casedispose.strategy;

import com.asset.dispoal.file.casedispose.dto.FileCaseConditionRequest;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.strategy.AbstractStrategyManager;
import tech.mhuang.pacebox.core.strategy.BaseStrategyManager;
import tech.mhuang.pacebox.core.util.ObjectUtil;
import tech.mhuang.pacebox.springboot.protocol.Result;

import javax.annotation.PostConstruct;
import java.util.Map;

@Component
public class FileUploadConditionStrategyManager extends AbstractStrategyManager<FileCaseConditionRequest, Result> implements BaseStrategyManager<FileCaseConditionRequest, Result>, ApplicationContextAware {

    private ApplicationContext applicationContext = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @PostConstruct
    @Override
    public void init() {
        Map<String, BaseFileUploadConditionStrategyServer> type = applicationContext.getBeansOfType(BaseFileUploadConditionStrategyServer.class);
        for (Map.Entry<String, BaseFileUploadConditionStrategyServer> entry : type.entrySet()) {
            BaseFileUploadConditionStrategyServer caseTypeStrategyServer = entry.getValue();
            if (ObjectUtil.isEmpty(caseTypeStrategyServer.event())) {
                continue;
            }
            caseTypeStrategyServer.event().forEach(event -> set(event, caseTypeStrategyServer));
        }
    }
}